﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.User.Contact
{
    using SharingCenter.Web.Classes;
    using SharingCenter.Web.Classes.Contact;
    using SharingCenter.Web.Classes.enums;

    public partial class Default : ContactPageBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ListView1.ItemCommand += new EventHandler<ListViewCommandEventArgs>(ListView1_ItemCommand);
        }

        void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "DeleteContact":
                    using (scDataContext cxt = new scDataContext())
                    {
                        cxt.DeleteContact(Profile.UserId, new Guid(e.CommandArgument.ToString()));
                    }
                    SetTopMostMessage("好友已删除。", true);
                    RefreshPage();
                    break;
                default: break;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindContactList();
        }

        private void BindContactList()
        {
            ListView1.DataSource = ContactOperations.GetContactsWithDetails(Profile.UserId);
            ListView1.DataBind();
        }
    }
}
